home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / filestatus / files.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  3.7 KB  |  187 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <functions.h>
  6. #define NL NULL
  7. void free_pdir();
  8. static struct FileLock      *pdir = NL;
  9. static struct FileInfoBlock *dir_info = NL;
  10. char image[200];
  11. void sr(char *str);
  12. void CheckFiles(void);
  13. void end();
  14. void StripSlash(char *str);
  15. void CheckForDirs(char PathsFile[]);
  16. int Strncmp(char *str1,char *str2,int i);
  17. void free_pdir();
  18. int NumDirs;
  19. main(int argc,char *argv[])
  20. {
  21.   if(argc!=2)
  22.   {
  23.         printf("FileStatus v1.0, written by Joseph Hodge\n");
  24.         printf("Usage: FileStatus <conference path>\n");
  25.         printf("   ie: FileStatus BBS:PD\n");
  26.         printf("\n");
  27.         exit(0);
  28.   }
  29.  strcpy(image,argv[1]);
  30.  sr(image);
  31.  if ((dir_info =(struct FileInfoBlock *)AllocMem((long)sizeof(struct FileInfoBlock),0L)) == NULL)
  32.    {
  33.      printf("Memory Allocation Error.\n");
  34.      Delay(300L);
  35.      exit(0);
  36.    }
  37.   printf("\nFileStatus v1.0, written by Joseph Hodge\n");
  38.   printf("\n\nPerforming validation..\n\n");
  39.    CheckFiles();
  40.    end();
  41. }
  42.  
  43. void CheckFiles(void)
  44. {
  45.    FILE *fi;
  46.    char PathsFile[200];
  47.    char Dirs[200];
  48.    sprintf(Dirs,"%s/ndirs",image);
  49.    sprintf(PathsFile,"%s/Paths",image);
  50.    
  51.    if(access(PathsFile,00))
  52.    {
  53.      printf("Can't locate paths file\n");
  54.      printf("Please check to insure the conference path was correct. IE:\n");
  55.      printf("BBS:PD\n");
  56.      end();
  57.    }
  58.    if(access(Dirs,00))
  59.    {
  60.     printf("Can't locate ndirs file\n");
  61.      printf("Please check to insure the conference path was correct. IE:\n");
  62.      printf("BBS:PD\n");
  63.      end();
  64.    }
  65.    fi=fopen(Dirs,"r");
  66.    fgets(Dirs,80,fi);
  67.    fclose(fi);
  68.    NumDirs=atoi(Dirs);
  69.    fi=fopen(PathsFile,"r");
  70.    while(fgets(PathsFile,80,fi)!=NULL)
  71.    {
  72.       sr(PathsFile);
  73.       StripSlash(PathsFile);
  74.       CheckForDirs(PathsFile);
  75.    }
  76.    fclose(fi);
  77. }
  78. void StripSlash(char *str)
  79. {
  80.    register int i;
  81.    i=strlen(str)-1;
  82.    if(*(str+i)=='/') *(str+i)='\0';
  83. }
  84.  
  85. void CheckForDirs(char PathsFile[])
  86. {
  87.    FILE *fi;
  88.    int NumFiles=0;
  89.    int Missing=0;
  90.    printf("Scanning %s...\n",PathsFile);
  91.    if (! (pdir=(struct FileLock *)Lock(PathsFile,(ULONG)ACCESS_READ)) )
  92.    {
  93.      free_pdir();
  94.        return;
  95.    }
  96.     if ( ! Examine((BPTR)pdir, dir_info) )
  97.     {
  98.       free_pdir();
  99.       return;
  100.     }
  101.     while(ExNext((BPTR)pdir,dir_info))
  102.    {
  103.     if(dir_info->fib_DirEntryType < 0L )
  104.     {
  105.       NumFiles +=1;
  106.       if(!ScanDirs(dir_info->fib_FileName))
  107.       {
  108.          printf("\n  %s missing from dir files\n",dir_info->fib_FileName);
  109.          Missing +=1;
  110.       }
  111.     }
  112.    }
  113.    printf("  Total Files %d, Total missing %d\n\n",NumFiles,Missing);
  114.    free_pdir();
  115. }
  116.  
  117. int ScanDirs(char str[])
  118. {
  119.   FILE *fi;
  120.   int i;
  121.   char DirFile[200];
  122.   i=1;
  123.   strupr(str);
  124.   while(i<=NumDirs)
  125.   {
  126.     sprintf(DirFile,"%s/dir%d",image,i);
  127.     if(!access(DirFile,00))
  128.     {
  129.        fi=fopen(DirFile,"r");
  130.        while(fgets(DirFile,100,fi)!=NULL)
  131.        {
  132.           strupr(DirFile);
  133.           if(!Strncmp(DirFile,str,strlen(str)))
  134.           {
  135.              fclose(fi); return(1);
  136.           }
  137.        }
  138.        fclose(fi);
  139.      }
  140.      i++;
  141.    }
  142.    return(0);
  143. }
  144. void sr(char *str)
  145. {
  146.    register int i;
  147.    i=strlen(str)-1;
  148.    while(i)
  149.    {
  150.       if(*(str+i)<=32) *(str+i)='\0'; else return;
  151.       i--;
  152.    }
  153. }
  154. int Strncmp(char *str1,char *str2,int i)
  155. {
  156.    register int j=0;
  157.    while(j<i)
  158.    {
  159.      if(*(str1+j)==*(str2+j)) j +=1; else break;
  160.    }
  161.    if(j==i) return(0); else return(1);
  162.  
  163. /*
  164.   while(i>0 && *(str1+i-1)==*(str2+i-1)) i -=1;
  165.   return(i);
  166. */
  167. }
  168.  
  169. void end()
  170. {
  171.    free_pdir();
  172.   if(dir_info!=NL)
  173.   {
  174.    
  175.    FreeMem(dir_info,(long)sizeof(struct FileInfoBlock));
  176.   }
  177.  exit(0);
  178. }
  179. void free_pdir()
  180. {
  181.    if ( pdir )
  182.       {
  183.       UnLock((BPTR)pdir);
  184.       pdir=NL;
  185.        }
  186.    return;   
  187. }